#include "process_pool.h"

int tran_file(int new_fd)
{
    //先发送文件名给客户端
    train_t t;
    t.data_len=strlen(FILENAME);//文件名长度装在火车头
    strcpy(t.buf,FILENAME);//文件内容放在火车上
    int ret=send(new_fd,&t,4+t.data_len,0);//发送文件名给客户端
    ERROR_CHECK(ret,-1,"send");
    //发送文件内容
    int fd=open(FILENAME,O_RDONLY);
    ERROR_CHECK(fd,-1,"open");
    while(t.data_len=read(fd,t.buf,sizeof(t.buf)))
    {
        send(new_fd,&t,4+t.data_len,0);
    }
    t.data_len=0;
    ret=send(new_fd,&t,4+t.data_len,0);//发送一个空火车头到客户端，即文件内容发送完成标志
    ERROR_CHECK(ret,-1,"send");
    return 0;
}
